﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace LyncServerExtension.Plugin.JSON
{
    /// <summary>
    /// Class to represent a json object result.
    /// </summary>
    public class JSONObject : ILyncResult
    {
        private string literalValue;

        /// <summary>
        /// Gets the mime-type.
        /// </summary>
        /// <value>
        /// The mime-type of the result.
        /// </value>
        public string MimeType
        {
            get { return "application/json"; }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="JSONObject"/> class.
        /// </summary>
        /// <param name="literalValue">The literal value.</param>
        internal JSONObject(string literalValue)
        {
            this.literalValue = literalValue;
        }

        /// <summary>
        /// Writes this result to the given stream.
        /// </summary>
        /// <param name="stream">The stream.</param>
        public void Write(Stream stream)
        {
            byte[] bytes = Encoding.UTF8.GetBytes(literalValue);
            stream.Write(bytes, 0, bytes.Length);
        }
    }
}
